<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <script src="./js/earthsdk.js"></script>
    <!-- 自定义Css样式 -->
    <link rel="stylesheet" href="./css/example1.css">
    <title>动态创建自定义Actor</title>
    <style>
        html,
        body,
        #app {
            width: 100%;
            height: 100%;
            margin: 0px;
            padding: 0px;
        }

        .box>div {
            display: grid;
            grid-template-columns: 100px 1fr;
            align-items: center;
        }

        .box>button {
            width: 100%;
            margin-top: 5px;
        }

        .tip {
            color: rgb(255, 255, 0);
            font-size: 14px;
            padding-bottom: 10px;
            border-bottom: 2px dotted #979797;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <div id="panel">
        <H3>动态创建自定义Actor</H3>
        <p class="tip">引用路径：UE编辑器，资产右键【复制引用】</p>
        <div class="box">
            <div><label for="">引用路径：</label>
                <input id="actorClass" type="text"
                    value="Blueprint'/Game/BasicContent/Human/Pedestrian/Bp_Pedestrian.Bp_Pedestrian'">
            </div>
            <button onclick="createFromActorClass()">开始创建</button>
            <button onclick="flyIn()">飞入UE的初始视角</button>
        </div>
    </div>
    <script>
        /** ---------------------------------地球创建------------------------------------**/

        // Vue中引入方式：import { ESObjectsManager } from 'esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main';

        const { ESObjectsManager } = XE2['esobjs-xe2-plugin-main']
        const objm = new ESObjectsManager();
        window.g_objm = objm;

        // 监听视口创建完成事件
        objm.viewerCreatedEvent.don((viewer) => {
            objm.activeViewer.defaultCameraFlyIn()
        })

        // 通过json创建一个影像图层
        const imageryLayer = objm.createSceneObjectFromJson({
            "id": "9812a65f-0de0-4f7b-b234-809c0c2fb8ef",
            "type": "ESImageryLayer",
            "maximumLevel": 18,
            "url": "https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}"
        });


        /** ---------------------------------!!!actor仅支持UE引擎------------------------------------**/

        // 根据UE资产创建Actor
        const { ESUnrealActor } = XE2['esobjs-xe2-plugin-main']
        function createFromActorClass() {
            const actor = objm.createSceneObject(ESUnrealActor)
            // UE的资产引用路径
            actor.actorClass = document.getElementById("actorClass").value
            // 编辑
            actor.editing = true
        }

        // 飞到初始视角
        function flyIn() {
            objm.activeViewer.defaultCameraFlyIn()
        }








    </script>

    <!-- UE引擎面板组件 -->
    <div id="root">
        <create-ue-engine :objm="objm"></create-ue-engine>
    </div>
    <!-- Vue文件 -->
    <script src="./js/vue.global.js"></script>
    <!-- 切换UE和Cesium的组件 -->
    <script src="./js/createUeEngine.js"></script>
</body>

</html>